import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yp/config/config.dart';
import 'package:yp/helper.dart';
import 'package:yp/logic.dart';
import 'package:get/get.dart';

import '../../../router.dart';
import 'logic.dart';
import 'state.dart';

class SetUpPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SetUpPage();
  }
}

class _SetUpPage extends State<SetUpPage> {
  final SetUpLogic logic = Get.put(SetUpLogic());
  final SetUpState state = Get.find<SetUpLogic>().state;
  final GlobalLogic logic1 = Get.put(GlobalLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        centerTitle: true,
        elevation: 0,
        backgroundColor: Color(0xffea5504),
        title: Text(
          '系统设置',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
          ),
        ),
      ),
      body: GetBuilder<SetUpLogic>(
        builder: (logic) {
          return Container(
            color: Colors.white,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // SizedBox(
                //   height: setWidth(120),
                // ),
                // Padding(
                //   padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                //   child: InkWell(
                //     onTap: () {
                //       print('========================== 发票抬头管理 ==========================');
                //     },
                //     child: Container(
                //       height: setWidth(82),
                //       padding: EdgeInsets.only(
                //         bottom: setWidth(10),
                //       ),
                //       child: Row(
                //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //         children: [
                //           Text(
                //             '发票抬头管理',
                //             style: TextStyle(
                //               color: Color(0xff222222),
                //               fontSize: 14,
                //             ),
                //           ),
                //           Image.asset(
                //             'assets/images/icon-left.png',
                //             width: setWidth(10),
                //             height: setWidth(18),
                //             color: Color(0xffadadad),
                //             fit: BoxFit.cover,
                //           )
                //         ],
                //       ),
                //     ),
                //   ),
                // ),
                // Divider(
                //   height: setWidth(1),
                //   indent: setWidth(20),
                //   endIndent: 0,
                //   color: Color(0xffeeeeee),
                // ),

                // Padding(
                //   padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                //   child: InkWell(
                //     onTap: () {
                //       Get.toNamed(RouteConfig.webview, arguments: {
                //         "url":
                //             "https://img.zrhsh.com/zrhshgg/treaty/yszc-hxk.html",
                //       });
                //     },
                //     child: Container(
                //       height: setWidth(82),
                //       padding: EdgeInsets.only(
                //         bottom: setWidth(10),
                //       ),
                //       child: Row(
                //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //         children: [
                //           Text(
                //             '隐私协议',
                //             style: TextStyle(
                //               color: Color(0xff222222),
                //               fontSize: 14,
                //             ),
                //           ),
                //           Image.asset(
                //             'assets/images/icon-left.png',
                //             width: setWidth(10),
                //             height: setWidth(18),
                //             color: Color(0xffadadad),
                //             fit: BoxFit.cover,
                //           )
                //         ],
                //       ),
                //     ),
                //   ),
                // ),
                // Divider(
                //   height: setWidth(1),
                //   indent: setWidth(20),
                //   endIndent: 0,
                //   color: Color(0xffeeeeee),
                // ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                  child: InkWell(
                    onTap: () {
                      print(
                          '========================== 关于我们 ==========================');
                      Get.toNamed(RouteConfig.about);
                    },
                    child: Container(
                      height: setWidth(82),
                      padding: EdgeInsets.only(
                        bottom: setWidth(10),
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '关于我们',
                            style: TextStyle(
                              color: Color(0xff222222),
                              fontSize: 14,
                            ),
                          ),
                          Image.asset(
                            'assets/images/icon-left.png',
                            width: setWidth(10),
                            height: setWidth(18),
                            color: Color(0xffadadad),
                            fit: BoxFit.cover,
                          )
                        ],
                      ),
                    ),
                  ),
                ),
                Divider(
                  height: setWidth(1),
                  indent: setWidth(20),
                  endIndent: 0,
                  color: Color(0xffeeeeee),
                ),
                // Padding(
                //   padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                //   child: InkWell(
                //     onTap: () {
                //       print(
                //           '========================== 注册协议 ==========================');
                //       Get.toNamed(RouteConfig.webview, arguments: {
                //         "url":"https://img.zrhsh.com/zrhshgg/treaty/fwxy.html",
                //
                //       });
                //     },
                //     child: Container(
                //       height: setWidth(82),
                //       padding: EdgeInsets.only(
                //         bottom: setWidth(10),
                //       ),
                //       child: Row(
                //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //         children: [
                //           Text(
                //             '注册协议',
                //             style: TextStyle(
                //               color: Color(0xff222222),
                //               fontSize: 14,
                //             ),
                //           ),
                //           Image.asset(
                //             'assets/images/icon-left.png',
                //             width: setWidth(10),
                //             height: setWidth(18),
                //             color: Color(0xffadadad),
                //             fit: BoxFit.cover,
                //           )
                //         ],
                //       ),
                //     ),
                //   ),
                // ),
                Divider(
                  height: setWidth(1),
                  indent: setWidth(20),
                  endIndent: 0,
                  color: Color(0xffeeeeee),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                  child: Container(
                    height: setWidth(82),
                    padding: EdgeInsets.only(
                      bottom: setWidth(10),
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          '客服热线',
                          style: TextStyle(
                            color: Color(0xff222222),
                            fontSize: 14,
                          ),
                        ),
                        Text('0755-83586686')
                      ],
                    ),
                  ),
                ),
                Divider(
                  height: setWidth(1),
                  indent: setWidth(20),
                  endIndent: 0,
                  color: Color(0xffeeeeee),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                  child: InkWell(
                    onTap: () {
                      print(
                          '========================== 发票抬头管理 ==========================');
                      Get.toNamed(RouteConfig.invoiceHeaderManagement,
                          arguments: {'chooseType': false});
                    },
                    child: Container(
                      height: setWidth(90),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '发票抬头管理',
                            style: TextStyle(
                              color: Color(0xff222222),
                              fontSize: 14,
                            ),
                          ),
                          Image.asset(
                            'assets/images/icon-left.png',
                            width: setWidth(10),
                            height: setWidth(18),
                            color: Color(0xffadadad),
                            fit: BoxFit.cover,
                          )
                        ],
                      ),
                    ),
                  ),
                ),
                Divider(
                  height: setWidth(1),
                  indent: setWidth(20),
                  endIndent: 0,
                  color: Color(0xffeeeeee),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                  child: InkWell(
                    onTap: () {
                      print(
                          '========================== 账号注销 ==========================');
                      Get.toNamed(RouteConfig.accountInvalid2);
                    },
                    child: Container(
                      height: setWidth(90),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '注销账号',
                            style: TextStyle(
                              color: Color(0xff222222),
                              fontSize: 14,
                            ),
                          ),
                          Image.asset(
                            'assets/images/icon-left.png',
                            width: setWidth(10),
                            height: setWidth(18),
                            color: Color(0xffadadad),
                            fit: BoxFit.cover,
                          )
                        ],
                      ),
                    ),
                  ),
                ),
                Divider(
                  height: setWidth(1),
                  indent: setWidth(20),
                  endIndent: 0,
                  color: Color(0xffeeeeee),
                ),

                SizedBox(
                  height: setWidth(50),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: setWidth(50)),
                  child: InkWell(
                    onTap: () {
                      print('******************** 退出登录 ********************');
                      showDialog(
                        context: context,
                        builder: (BuildContext context) {
                          return CupertinoAlertDialog(
                            title: Text("提示"),
                            content: Column(
                              children: <Widget>[
                                SizedBox(
                                  height: 10,
                                ),
                                Align(
                                  child: Text("是否退出登录？"),
                                  alignment: Alignment(0, 0),
                                ),
                              ],
                            ),
                            actions: <Widget>[
                              CupertinoDialogAction(
                                child: Text("取消"),
                                onPressed: () {
                                  Navigator.pop(context);
                                  print("取消");
                                },
                              ),
                              CupertinoDialogAction(
                                child: Text("确定"),
                                onPressed: () {
                                  logic1.logout();
                                },
                              ),
                            ],
                          );
                        },
                      );
                    },
                    child: Container(
                      height: setWidth(88),
                      decoration: BoxDecoration(
                        color: Config.mainColor,
                        borderRadius: BorderRadius.circular(setWidth(10)),
                      ),
                      alignment: Alignment.center,
                      child: Text(
                        '退出登录',
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 17,
                        ),
                      ),
                    ),
                  ),
                ),
                SizedBox(
                  height: setWidth(10),
                ),
                Container(
                  padding: EdgeInsets.only(bottom: 10),
                  child: Center(
                    child: Text(
                        "版本：${logic.state.version} ${Config.env == 1 ? '(${logic.state.buildNumber})（Beta）' : Config.env == 2 ? '(${logic.state.buildNumber})（UAT）' : Config.env == 4 ? '(${logic.state.buildNumber})（Test）' : ''}",
                    ),
                  ),
                )
              ],
            ),
          );
        },
      ),
    );
  }
}
